using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Hexagonal
{
	public class HexState
	{
		private System.Drawing.Color backgroundColor;
        private System.Drawing.Color borderColor;
        private Bitmap backgroundImage;
        
        /*
         *  Special hexes <specialhex>:
         *      0 normal hex
         *      1 blocked - Nothing can pass the hex
         *      2 fastpass - Creeps speed up when they pass
         *      3 healpass - Creeps heal when they pass
         *      4 pass - Creeps can pass, but no towers can be placed
         *  Spawn/Exit Hexes <spawnhex> <exithex>:
         *      5 Spawnhex - Creeps spawn here {each spawn hex must be linked to an exit hex}
         *      6 Exithex - Creeps exit here
         *  Tower Hexes <placetower>:
         *      7 Towerhex (POP only - for now) - A tower is placed on this hex
         *  
         *  Types of towers:
         *      POP
         *      THUMP
         *      SHOCK
         *      MISSILE
         *      LASER
         *      BLASTER
         *      
         *  Types of creeps:
         *      CHOMPER
         *      SPINNER
         *      WIGGLE
         *      STAR
         *      CUBIC
         *      PULSAR
         *      SWARM
         */
        private int hexType = 0;

        private Hex exitHex;
        private int hexID;
        private bool locked = false;
        private bool outside = false;

        #region Properties

        public System.Drawing.Color BackgroundColor
		{
			get
			{
				return backgroundColor;
			}
			set
			{
				backgroundColor = value;
			}
		}

        public System.Drawing.Color BorderColor
        {
            get
            {
                return borderColor;
            }
            set
            {
                borderColor = value;
            }
        }

        public Bitmap BackgroundImage
        {
            get
            {
                return backgroundImage;
            }
            set
            {
                backgroundImage = value;
            }
        }

        public int HexType
        {
            get
            {
                return hexType;
            }
            set
            {
                if (this.outside && !this.locked && !(value >= 5 && value <= 6))
                    if(value > 0)
                        throw new Exception("This hex is outside, so it may only be a spawn or an exit.");

                if (!this.locked)
                {
                    if (value >= 0 && value <= 7)
                        hexType = value;
                    else throw new Exception("Invalid hex type given");

                    int alpha = 180;

                    switch (hexType)
                    {
                        // blocked
                        case 1:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.nopass;
                            this.backgroundColor = Color.FromArgb(alpha, 0, 71, 66);
                            break;

                        // fastpass
                        case 2:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.fastpass;
                            this.backgroundColor = Color.FromArgb(alpha, 0, 93, 123);
                            break;

                        // healpass
                        case 3:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.healpass;
                            this.backgroundColor = Color.FromArgb(alpha, 87, 19, 149);
                            break;

                        // pass
                        case 4:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.pass;
                            this.backgroundColor = Color.FromArgb(alpha, 143, 92, 5);
                            break;

                        // spawnhex
                        case 5:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.spawn1;
                            this.backgroundColor = Color.FromArgb(alpha, 0, 150, 2);
                            break;

                        // exithex
                        case 6:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.exit1;
                            this.backgroundColor = Color.FromArgb(alpha, 97, 27, 6);
                            break;

                        // POP tower
                        case 7:
                            this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.vortex1;
                            this.backgroundColor = Color.FromArgb(alpha, 237, 13, 91);
                            break;

                        // default (standard hex)
                        default:
                            if (this.outside)
                            {
                                Outside = true;
                            }
                            else
                            {
                                this.backgroundImage = null;
                                this.backgroundColor = Color.FromArgb(alpha, 0, 20, 5);
                            }
                            break;
                    }
                }
                else throw new Exception("The hex is locked - you may not change this hex.");
            }
        }

        public int HexID
        {
            get
            {
                return hexID;
            }
            set
            {
                hexID = value;
            }
        }

        public Hex ExitHex
        {
            get
            {
                return exitHex;
            }
            set
            {
                exitHex = value;
            }
        }

        public bool Locked
        {
            get
            {
                return locked;
            }
            set
            {
                locked = value;
                if (value)
                {
                    this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.lockedHex;
                    this.backgroundColor = Color.FromArgb(0, 0, 0);
                }
            }
        }

        public bool Outside
        {
            get
            {
                return outside;
            }
            set
            {
                outside = value;
                if (value)
                {
                    this.backgroundImage = (Bitmap)global::GeoSwarm_Editor.Properties.Resources.outsideHex;
                    this.backgroundColor = Color.FromArgb(0, 71, 66);
                }
            }
        }

        #endregion

        public HexState(Color backgroundColor, Color borderColor)
		{
            this.backgroundColor = backgroundColor;
            this.borderColor = borderColor;
		}

        public HexState(Color backgroundColor)
        {
            this.backgroundColor = backgroundColor;
        }
	}
}
